package leetcode;

public class Head {
    // 构造偶数个链表
    public static ListNode genList(){
        ListNode node1 = new ListNode(1);
        ListNode node2 = new ListNode(2);
        ListNode node3 = new ListNode(3);
        ListNode node4 = new ListNode(4);
        node1.next = node2;
        node2.next = node3;
        node3.next = node4;
        node4.next = null;
        return node1;
    }

    // 构造奇数个链表
    public static ListNode genListEven(){
        ListNode node1 = new ListNode(1);
        ListNode node2 = new ListNode(2);
        ListNode node3 = new ListNode(3);
        ListNode node4 = new ListNode(4);
        ListNode node5 = new ListNode(5);
        node1.next = node2;
        node2.next = node3;
        node3.next = node4;
        node4.next = node5;
        node5.next = null;
        return node1;
    }

    /**
     * 回文奇数个
     * @return
     */
    public static ListNode genListPalidOdd(){
        ListNode node1 = new ListNode(1);
        ListNode node2 = new ListNode(2);
        ListNode node3 = new ListNode(2);
        ListNode node4 = new ListNode(1);
        node1.next = node2;
        node2.next = node3;
        node3.next = node4;
        node4.next = null;
        return node1;
    }

    // 构造回文偶数个链表
    public static ListNode genListPalidEven(){
        ListNode node1 = new ListNode(1);
        ListNode node2 = new ListNode(2);
        ListNode node3 = new ListNode(3);
        ListNode node4 = new ListNode(2);
        ListNode node5 = new ListNode(1);
        node1.next = node2;
        node2.next = node3;
        node3.next = node4;
        node4.next = node5;
        node5.next = null;
        return node1;
    }

    public static ListNode genList(int[] arr) {
        ListNode head = new ListNode(-1);
        ListNode cur = head;
        for (int i=0; i<arr.length; i++) {
            cur.next = new ListNode(arr[i]);
            cur = cur.next;
        }
        return head.next;
    }

    // 输出链表
    public static void printList(ListNode head){
        while (head != null){
            System.out.println(head.val);
            head = head.next;
        }
    }
}
